/**
 * 
 */
package com.sad.controller.action;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sad.util.G;

/**
 * 
 * 一个简单的MVC
 * 
 * @author zhaoqy
 *
 */
public class ActionManager {

	private static Logger logger = LoggerFactory.getLogger(ActionManager.class);

	private static final Map<String, IAction> CONTROLLER = new HashMap<String, IAction>();

	/**
	 * 
	 * @param name
	 * @return
	 */
	public static IAction allo(String name) {
		String className = G.system.controller_package + "." + StringUtils.capitalize(name) + "Action";
		IAction p = CONTROLLER.get(className);
		if (p != null) {

			if (logger.isDebugEnabled()) {
				logger.debug("get service from cache : ", className);
			}

			return p;
		}

		try {
			p = (IAction) Class.forName(className).newInstance();
			CONTROLLER.put(className, p);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}

		return p;
	}
}
